import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-01-04
 * Time:16:59
 */
class Solution {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> list=new LinkedList<>();
        List<Integer> list1=new LinkedList<>();
        list1.add(1);
        list.add(list1);
        if(numRows<1){
            return list;
        }
        for (int i = 1; i < numRows; i++) {
            List<Integer> cur=new LinkedList<>();
            cur.add(1);
            for (int j = 1; j < i; j++) {
                cur.add(list.get(i-1).get(j)+list.get(i-1).get(j-1));
            }
            cur.add(1);
            list.add(cur);
        }
        return list;
    }
}
class Solution1 {
    public int removeElement(int[] nums, int val) {
        int sum= nums.length;
        if(sum==0){
            return 0;
        }
        int left=0;
        int right=sum-1;
        while(left<right){
            if(nums[left]==val&&nums[right]!=val){
                nums[left]=nums[right];
                nums[right]=0;
                left++;
                right--;
                sum--;
            }
            if(nums[left]!=val){
                left++;
            }
            if(nums[right]==val){
                nums[right]=0;
                right--;
                sum--;
            }

        }
        if(nums[right]==val){
            nums[right]=0;
            sum--;
        }
        return sum;
    }
}
class Solution2 {
    public int removeDuplicates(int[] nums) {
        if(nums.length<2){
            return nums.length;
        }
        int sum=0;
        int cur=1;
        //一直找到相等的
        while(nums[cur]!=nums[sum]){
            cur++;
            sum++;
            if(cur>= nums.length){
                break;
            }
        }
        while(cur<nums.length){
            int pre=sum+1;
            if(nums[cur]==nums[sum]){
                cur++;
            }else{
                nums[pre]=nums[cur];
                sum++;
            }
        }
        return sum+1;
    }
}
public class Test {
}
